package com.oromwin.repos.server.response.volume;

import java.io.DataInputStream;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;

import com.oromwin.repos.common.Logger;
import com.oromwin.repos.common.ReposException;
import com.oromwin.repos.common.helper.IOHelper;
import com.oromwin.repos.data.MediaTable;
import com.oromwin.repos.server.response.NormalResponse;

public class ListVolumeResponse extends NormalResponse {
    private Log log = Logger.getLog(ListVolumeResponse.class);
    private int size = 0;
    private List mediaTableList = null;
    
    public ListVolumeResponse() {
        mediaTableList = new ArrayList();
    }
    
    public void receive(DataInputStream dis) throws ReposException {
        try {
            Result = dis.readBoolean();
            Description = IOHelper.readUTF8(dis);
            size = dis.readInt();
            for (int i = 0; i < size; i++) {
                String volumeId = IOHelper.readUTF8(dis);
                String mediaId = IOHelper.readUTF8(dis);
                File mediaPath = new File(IOHelper.readUTF8(dis));
                Long mediaMaxBytes = new Long(dis.readLong());
                Long mediaUsedBytes = new Long(dis.readLong());
                Integer mediaFileCount = new Integer(dis.readInt());
                Boolean mediaStatus = new Boolean(dis.readBoolean());
                String mediaCreateDate = IOHelper.readUTF8(dis);
                String mediaUpdateDate = IOHelper.readUTF8(dis);
                MediaTable mediaTable = new MediaTable(volumeId, mediaId, mediaPath, mediaMaxBytes, mediaUsedBytes, mediaFileCount, mediaStatus, mediaCreateDate, mediaUpdateDate);
                mediaTableList.add(mediaTable);
            }
        } catch (IOException e) {
            throw ReposException.create(log, e);
        }
    }
    
    public List getMediaTableList() {
        return mediaTableList;
    }
}
